package com.common.project.util;



import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * Created by admin on 2019/06/17.
 */
public class UniqueUtil {


	/**
	 * 生成UUID
	 *
	 * @return
	 */
	public static String generateUUID() {
		String uuid = UUID.randomUUID().toString();
		uuid = uuid.replaceAll("-","");
		return uuid;
	}

	/**
	 * 生成UUID
	 *
	 * @return
	 */
	public static String generateSix() {
		Random random = new Random();
		int x = random.nextInt(899999);
		x = x + 100000;
		return String.valueOf(x);
	}

	/**
	 * 生成唯一令牌
	 *
	 * @return
	 */
	public static String generateToken(String username,String passwaor) {
		String str= username+passwaor+System.currentTimeMillis();
		return MD5Util.MD5(str);
	}

	/**
	 * 生成订单号
	 *
	 * @return
	 */
	public static String generateOrderNumber() {
		DateFormat formater = new SimpleDateFormat("yyyyMMddHHmmssSSSS");
		StringBuilder sb = new StringBuilder(formater.format(new Date()));
		return sb.toString();
	}

	/**
	 * 生成订单编号
	 * 
	 * @return
	 */
	public static String getOrderNo() {
		String orderNo = new SimpleDateFormat("yyyyMMddHHmmssSSSS").format(new Date());
		int radomInt = new Random().nextInt(9999);
		return orderNo += radomInt;
	}

	/**
	 * 生成订单编号
	 * 
	 * @return
	 */
	public static String getSimOrderNo() {
		String orderNo = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
		int radomInt = new Random().nextInt(99);
		return orderNo += radomInt;
	}

	public static void main(String[] args) {
		String s = UniqueUtil.generateUUID();
		System.out.println(s);//51626ff9dd4a4a3da84845eb94d59c32
		String simOrderNo = UniqueUtil.getSimOrderNo();
		System.out.println(simOrderNo);//2018010914210817
		String s1 = UniqueUtil.generateSix();
		System.out.println(s1);//263870
		String s2 = UniqueUtil.generateOrderNumber();
		System.out.println(s2);//201801091421080881
		String orderNo = UniqueUtil.getOrderNo();
		System.out.println(orderNo);//2018010914210808825073

	}
}
